/*
 * MyComponentInfo.java
 *
 * Created on May 11, 2000, 12:47 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

//package javaapplication1;
import java.util.*;
import java.awt.*; 
import javax.swing.*;
import java.lang.*;
import java.awt.event.*;

/**
 *
 * @author ayman
 *
 * The class MyComponentInfo is resposable for saving the data and returns
 * component that shows and handel the information about the object
 */
public class MyComponentInfo {
    
    
            // data
    private Vector compVector = new Vector();
    private Vector temp = new Vector (); // this vector is made to get the info
    //for specific com
    private MyComponentContainer comp;
    private String name;
    private MyButtonSpecialInfo buttonInfo ;
    private MyTextFieldSpecialInfo textInfo;
    private MyLabelSpecialInfo labelInfo;
    private MyCheckBoxSpecialInfo checkBoxInfo;
    private MyRadioButtonSpecialInfo radioButtonInfo;
    
    /** Creates a new instance of MyComponentInfo */
     public MyComponentInfo (MyComponentContainer comp,JFrame propertiesFrame, String tableName) {
        this.comp = comp;
         handleCompName();
         handleCompSize();
         HandleCompAligment();
         HandleIsEnable();
         if ((comp instanceof MyButtonContainer)  ) {
            // System.out.println("button");
            buttonInfo = new MyButtonSpecialInfo ( (MyButtonContainer) comp,propertiesFrame);
            temp = buttonInfo.getInfoVector();
         }         
         
         if ((comp instanceof MyCheckBoxContainer)  ) {
            // System.out.println("button");
             Vector checkBoxTemp;
            buttonInfo = new MyButtonSpecialInfo ( (MyCheckBoxContainer) comp,propertiesFrame);
            temp = buttonInfo.getInfoVector();
            checkBoxInfo = new MyCheckBoxSpecialInfo ((MyCheckBoxContainer)comp, tableName);
            checkBoxTemp = checkBoxInfo.getInfoVector();
            for (int i=0; i < checkBoxTemp.size() ; i++ ) {
                temp.add(checkBoxTemp.elementAt(i));
            }
            
         }  
        if ((comp instanceof MyTextFieldContainer)  ) {
            // System.out.println("button");
            textInfo = new MyTextFieldSpecialInfo ( (MyTextFieldContainer) comp,propertiesFrame, tableName);
            temp = textInfo.getInfoVector();
         } 
         if ((comp instanceof MyLabelContainer)  ) {
            // System.out.println("button");
            labelInfo = new MyLabelSpecialInfo ( (MyLabelContainer) comp,propertiesFrame);
            temp = labelInfo.getInfoVector();
         } 
         if ((comp instanceof MyRadioButtonContainer)  ) {
            // System.out.println("button");
            radioButtonInfo = new MyRadioButtonSpecialInfo ( (MyRadioButtonContainer) comp, tableName);
            temp = radioButtonInfo.getInfoVector();
         } 
    }
    /**
     * This function is used to return the vector contains the format tab 
     * components
     */
     public Vector getCompoInfo() {
         for (int i =0; i < temp.size() ; i++) {
             compVector.add(temp.elementAt(i));
             //System.out.println(" it is elem # " + i);
         }
         return compVector;
     }

    
    
    //**************************************************************************
    /**
     * This Function is used to get the values inside the components that is 
     * used to show and edit the componenets info
     */ 
    public MyComponentContainer getNewInfoAndSave () {
        JTextField tempComp;
        Vector infoStringVector = new Vector();
        int width,height;
        double locX,locY;
        String compText;
         int isenable;

         //  Getting the new info
        for (int i=1 ; i < 10;i++,i++) {
            // System.out.println(" the is "+compVector.size());
            tempComp = (JTextField)compVector.elementAt(i);
            infoStringVector.add(tempComp.getText());
        }
         
         isenable = ((JComboBox)compVector.elementAt(11)).getSelectedIndex();
        
        // Setting the name
        comp.getComponent().setName((String)infoStringVector.elementAt(0));
        
        // Setting the size
        height = Integer.parseInt((String)infoStringVector.elementAt(1));
        width = Integer.parseInt((String)infoStringVector.elementAt(2));
        comp.getComponent().setSize(width,height);
        
        // Setting the location
        locX= Double.parseDouble((String)infoStringVector.elementAt(3));
        locY= Double.parseDouble((String)infoStringVector.elementAt(4));
        comp.getComponent().setLocation((int)locX,(int)locY);
        
        //Setting the (enable / disable ) button
        if (isenable==0) {
            comp.getComponent().setEnabled(true);
        } 
        else {
            comp.getComponent().setEnabled(false);
        }
        
        // Setting the name in case of the JButton
        if (comp instanceof MyButtonContainer) {
            buttonInfo.getAndSave();
        }
        if (comp instanceof MyTextFieldContainer) {
            textInfo.getAndSave();
           
        }
        if (comp instanceof MyLabelContainer) {
            labelInfo.getAndSave();
        }
        if (comp instanceof MyCheckBoxContainer) {
            checkBoxInfo.getAndSave();
        }
        if (comp instanceof MyRadioButtonContainer) {
            radioButtonInfo.getAndSave();
        }
        return comp;
    }
    
    
    //**************************************************************************
    /**
     *This function get the component name and create label and text area fot it
     */
    private void handleCompName () {
        JLabel compNameLabel = new JLabel ("Component Name :");
        compVector.addElement(compNameLabel);
        JTextField compNameTxtField = new JTextField (comp.getComponent().getName());
        compNameTxtField.setEditable(false);
        compNameTxtField.setSize(10,200);
        compVector.addElement(compNameTxtField);
    }

    
    //**************************************************************************
    /**
     *This function get the Height and size of the object
     */
    private void handleCompSize () {
        JLabel compHeight = new JLabel ("Height         :");
        compVector.addElement(compHeight);
        JTextField compHeightTxtField = new JTextField (Integer.toString(comp.getComponent().getSize().height));
                //(Integer.toString(comp.getSize().getWidth()));
        compVector.addElement(compHeightTxtField);
        JLabel compWidth = new JLabel ("Width          :");
        compVector.addElement(compWidth);
        JTextField compWidthTxtField = new JTextField (Integer.toString(comp.getComponent().getSize().width));
        compVector.addElement(compWidthTxtField);
        //compNameTxtField.setSize(10,200);
    }
    
    
    //**************************************************************************
    /**
     *This function get the aligment X and Y
     */
   private void HandleCompAligment () {
        JLabel compX = new JLabel ("X Position     :");
        compVector.addElement(compX);
        JTextField compXTxtField = new JTextField (String.valueOf(comp.getComponent().getLocation().getX()));
        compVector.addElement(compXTxtField);
        JLabel compY = new JLabel ("Y Position     :");
        compVector.addElement(compY);
        JTextField compYTxtField = new JTextField (String.valueOf(comp.getComponent().getLocation().getY()));
        compVector.addElement(compYTxtField);       
   }
   //**************************************************************************
    /**
     * This function get is enable the button 
     */
    private void HandleIsEnable () {
        JLabel compIsEnable = new JLabel ("Component Enable :");
        compVector.add(compIsEnable);
        String [] yesOrNo= new String [2];
        yesOrNo [0] = "YES";
        yesOrNo [1] = "NO";
        JComboBox isEnable = new JComboBox (yesOrNo);
        if (comp.getComponent().isEnabled()) {
            isEnable.setSelectedIndex(0);
        }
        else {
            isEnable.setSelectedIndex(1);
        }
        compVector.add(isEnable);
    }
    
    /**
     * This function is used to get the font and save the object in the vector
     */
    
    
}
